<!--
* 描述: 新建线索
* 创建人: hejin
-->
<template>
  <div class="app-container app-container-table">
    <crmGroupSubmit :formSubmitButton="formSubmitButton" />
    <el-form
      style="width:auto;border-radius: 4px;"
      class="editPer filter-params-crm-scroll crm-s-scroll edit"
    >
      <!-- 配置化接入 -->

      <!-- <div
          v-if="(infoComponents.formComponents?true:false)&&(infoComponents.formComponents[index+1].pageArea!=infoComponents.formComponents[index].pageArea)"
          class="filter-container-crm filter-title-crm">
          <i class="el-icon-edit"></i>
          {{infoComponents.formComponents[0].pageArea}}
      </div>-->

      <!-- <div :v-if="infoComponents.formComponents?true:false" class="filter-container-crm filter-params-crm">
          <crmGroupForm
            :dynamicComponentss="infoComponents.formComponents"
            :values="formField"
            ref="infoComponents-one"
          />
      </div>-->

      <!-- 本地接入 -->
      <div
        v-for="(item,index) in infoComponents"
        :key="index"
      >
        <div v-if="item.pageArea?true:false" class="filter-container-crm filter-title-crm">
          <!-- <i class="el-icon-edit"></i> -->
          {{item.pageArea}}
        </div>
        <div class="filter-container-crm filter-params-crm">
          <crmGroupForm
            :dynamicComponentss="item.tableComponents"
            :values="formField"
            :ref="'multipleTable'"
          />
          <span v-for="(item1,index) in item.children" :key="index+'chidren'">
            <crmGroupForm
              v-if="!(item1.type=='table')"
              :dynamicComponentss="item1.tableComponents"
              :values="formField"
              :ref="'multipleTable'"
            />
            <!-- <span>{{item1.type}}{{JSON.stringify(item1)}}</span>
            <span  v-if="!(item1.type=='table')">{{item1.type}}</span>-->
            <one-table-template
              v-if="item1.type=='table'"
              :ref="'multipleTable'+index"
              dynamicButtonsRight="[]"
              :dynamicApiConfig="item1.apiConfig"
              :dynamicTableCols="item1.tableCols"
              :dynamicFormFields="item1.formField"
              :dynamicIsShowSelect="false"
              :dynamicIsShowMoreBtn="true"
            />
          </span>
        </div>
      </div>
      <sendMsg ref="sendMsg"></sendMsg>
      <edit
        :dynamicEditRowData="editRowData"
        :popupsVisible="editPopupsVisible"
        :key="editPopupsKey"
        :popupsState="editPopupsState"
        @close="close"
        ref="addDlr"
      ></edit>
    </el-form>
  </div>
</template>
<script>
import { formMixins } from "@/components/mixins/formMixins";
import { oneTableTemplateMixins } from "@/components/mixins/oneTableTemplateMixins";
import { crmApis } from "@/api/apiList/crm";
import { requestAPI } from "@/api/commonRequest";
import crmGroupForm from "@/components/crm/commonComponents/crmGroupForm";
import crmGroupSubmit from "@/components/crm/commonComponents/crmGroupSubmit";
//import OneTableTemplate from "@/components/crm/table/crmOnetable";
import OneTableTemplate from "@/components/crm/Template/crmonePage";
import sendMsg from "@/components/crm/crmEjectWindows/crmCallandMsg/sendmsg";
import edit from "./crmDlrInput";
import Vue from "vue";
export default {
  name: "crmNewthread",
  // 组件混入对象
  mixins: [formMixins],
  components: {
    crmGroupForm,
    crmGroupSubmit,
    OneTableTemplate,
    sendMsg,
    edit
  },
  props: {},
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(
      ["crmNewthread"],
      function() {
        next();
      },
      false
    );
  },

  data() {
    let viewPageCode = "crmNewthread";

    if (
      this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
      this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
        .length > 0
    ) {
      let rowdatas = this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
        .formComponents;
      for (var i = 0; i < rowdatas.length; i++) {
        if (rowdatas[i].dataToObject) {
          for (let key in rowdatas[i].dataToObject) {
            let type = rowdatas[i].dataToObject[key].split("~")[0];
            let val = rowdatas[i].dataToObject[key].split("~")[1];
            switch (type) {
              case "fuc":
                rowdatas[i].dataToObject[key] = eval(val);
                break;
              case "bool":
                rowdatas[i].dataToObject[key] = val == "true" ? true : false;
                break;
              case "str":
                rowdatas[i].dataToObject[key] = val;
                break;
              default:
                rowdatas[i].dataToObject[key] = val;
                return;
            }
          }
          rowdatas[i] = Object.assign(rowdatas[i], rowdatas[i].dataToObject);
        }
      }
      this.$ConfigCache.CacheConfig.cacheData[
        viewPageCode
      ].formComponents = rowdatas;
    }

    return {
      editPopupsVisible:false,
      State: "",
      ismore: false,
      ismutiple: false,
      action: "", //证件上传地址
      accepttype:
        ".jpg,.jpeg,.png,.gif,.bmp,.pdf,.JPG,.JPEG,.PBG,.GIF,.BMP,.PDF", //上传文件类型
      text1: "选择文件",
      limit: 1,
      params: {},
      nagflag: true,
      posflag: false,
      flag: true,
      crmSourceFromThis: "",
      infoComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
          : [
              //客户信息 0
              {
                pageArea: "客户信息",
                tableComponents: [
                  {
                    compKey: "compKey1",
                    labelName: "客户名称",
                    codeField: "custName",
                    textField: "custName",
                    isRequire: true,
                    emitCode: (rowData, that) =>
                      this.getCustName1(rowData, that),
                    component: () =>
                      import("@/components/crm/crmEjectWindows/crmCustNameAdd"),
                    inputType: "inputText",
                    isMul: false,
                    isMust: false
                  },
                  {
                    compKey: "compKey2",
                    labelName: "电话",
                    codeField: "contactTel",
                    textField: "contactTel",
                    component: () =>
                      import("@/components/crm/crmEjectWindows/crmCallandMsg"),
                    inputType: "inputText",
                    isRequire: true,
                    validrule: {
                      noRequire: false,
                      isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
                    },
                    isMul: false,
                    isMust: false
                  },
                  {
                    compKey: "compKey3",
                    labelName: "性别",
                    codeField: "gender",
                    lookuptype: "DB0022",
                    isRequire: true,
                    isMust: true,
                    component: () =>
                      import("@/components/crm/lookupValue/lookupvalue")
                  },
                  {
                    compKey: "compKey4",
                    labelName: "备用电话",
                    codeField: "backupTel",
                    isMust: true,
                    isRequire: true,
                    validrule: {
                      noRequire: true,
                      isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
                    },
                    component: () =>
                      import("@/components/crm/textbox/crmTextInput")
                  },
                  {
                    compKey: "compKey5",
                    labelName: "用车人姓名",
                    codeField: "useCustName",
                    isMust: true,
                    component: () =>
                      import("@/components/crm/textbox/crmTextInput")
                  },
                  {
                    compKey: "compKey6",
                    labelName: "用车人电话",
                    codeField: "usePhone",
                    isRequire: true,
                    validrule: {
                      noRequire: true,
                      isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
                    },
                    isMust: true,
                    component: () =>
                      import("@/components/crm/textbox/crmTextInput")
                  },
                  {
                    compKey: "compKey7",
                    labelName: "用车人性别",
                    codeField: "useGenderCode",
                    lookuptype: "DB0022",
                    isRequire: false,
                    isMust: true,
                    component: () =>
                      import("@/components/crm/lookupValue/lookupvalue")
                  },

                  {
                    compKey: "compKey8",
                    labelName: "用车人备用电话",
                    codeField: "useBackupTel",
                    isMust: true,
                    isRequire: true,
                    validrule: {
                      noRequire: true,
                      isformat: /^((0\d{2,3}-\d{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/
                    },
                    component: () =>
                      import("@/components/crm/textbox/crmTextInput")
                  }
                ]
              },
              //服务信息 1
              {
                pageArea: "服务信息",
                tableComponents: [
                  {
                    compKey: "compKey5",
                    labelName: "信息来源",
                    codeField: "infoChanDCode",
                    textField: "infoChanName",
                    isRequire: true,
                    isMust: true,
                    isMul: false,
                    disabled: false,
                    component: () =>
                      import(
                        "@/components/crm/crmEjectWindows/crmSourceFrom/index"
                      ),
                    type: "propus",
                    emitCode: (rowData, _this) =>
                      this.changeSource(rowData, _this)
                  },
                  {
                    compKey: "compKey10",
                    labelName: "意向级别",
                    codeField: "clueLevelCode",
                    lookuptype: "LX141",
                    attribute: "1",
                    isRequire: true,
                    isMust: true,
                    component: () =>
                      import("@/components/crm/lookupValue/lookupvalue"),
                    changeCode: this.levelChange
                  },
                  // {
                  //   compKey: "compKey11",
                  //   labelName: "意向车系",
                  //   isMul: false,
                  //   isRequire: true,
                  //   codeField: "inteSeriesCode",
                  //   textField: "carSeriesCn",
                  //   emitCode: rowData => this.getCarSeries(rowData),
                  //   component: () =>
                  //     import(
                  //       "@/components/crm/crmEjectWindows/crmIntenCarSeries/index"
                  //     ),
                  //   inputType: "inputText",
                  //   isMust: false
                  // },
                  // {
                  //   compKey: "compKey12",
                  //   labelName: "意向车型",
                  //   isMul: false,
                  //   isRequire: true,
                  //   codeField: "inteTypeCode",
                  //   textField: "inteTypeName",
                  //   emitCode: rowData => this.getCarType(rowData),
                  //   component: () =>
                  //     import(
                  //       "@/components/crm/crmEjectWindows/crmCartype/index"
                  //     ),
                  //   inputType: "inputText",
                  //   isMust: false
                  // },
                  {
                    compKey: "compKey11",
                    labelName: "意向车系",
                    codeField: "carSeriesId",
                    textField: "carSeriesCn",
                    isRequire: true,
                    isMust: true,
                    isMul: false,
                    filterable:true,
                    lookuptype: crmApis.mdmVeCarSeriesQueryListForPage,
                    changeCode: this.serieSelect,
                    component: () => import("@/components/crm/lookupValue/singleDropList")
                  },
                  {
                    //compKey: "compKey60",
                    compKey: "carSeriesId",
                    labelName: "意向车型",
                    codeField: "smallCarTypeId",
                    textField: "smallCarTypeCn",
                    isRequire: true,
                    isMust: true,
                    isMul: false,
                    filterable:true,
                    lookuptype: crmApis.mdmVeColorChooseQueryList,
                    changeCodeArray: [
                      { changCode:"carSeriesId" }
                    ],
                    extralField:['carBrandCode','carSeriesCode','carSeriesId','smallCarTypeCode'],
                    extralParams:{carBrandCode: "1",isGroupByCarTypeId:"1"},
                    changeExtralField: this.carTypeSelect,
                    component: () => import("@/components/crm/lookupValue/secondDropList")
                  },
                  {
                    compKey: "compKey13",
                    labelName: "下次回访时间",
                    codeField: "nextCallbackDate",
                    isMust: true,
                    disabled: false,
                    isRequire: true,
                    component: () =>
                      import("@/components/crm/Time/crmafterDateTime")
                  }
                ],
                children: [
                  {
                    tableComponents: [
                      //5
                      {
                        compKey: "compKey14",
                        labelName: "描述",
                        codeField: "clueDesc",
                        inputType: "textarea",
                        span: 24,
                        isRequire: true,
                        // disabled: true,
                        component: () =>
                          import("@/components/crm/textbox/crmTextInput")
                      }
                    ]
                  },

                  {
                    tableComponents: [
                      {
                        compKey: "compKey15",
                        labelName: "备注",
                        codeField: "remark",
                        inputType: "textarea",
                        span: 24,
                        // disabled: true,
                        component: () =>
                          import("@/components/crm/textbox/crmTextInput")
                      }
                    ]
                  }
                ]
              }
              //线索详情  2
            ],

      formSubmitButton: [
        {
          compKey: "buttonKey3",
          text: "发送短信",
          size: "small",
          type: "",
          clickEvent: () => this.sendMessg(),
          isShow: true
        },
        {
          compKey: "buttonKey2",
          text: "保存",
          size: "small",
          type: "",
          clickEvent: () => this.save(),
          isShow: true
        }
        // {
        //   compKey: "buttonKey1",
        //   text: "线索培育",
        //   size: "small",
        //   type: "",
        //   clickEvent: () => this.jumpHref(),
        //   isShow: true
        // },
        // {
        //   compKey: "buttonKey3",
        //   text: "垂直媒体-店端主动录入",
        //   size: "small",
        //   type: "",
        //   clickEvent: () => this.dlrSave(),
        //   isShow: true
        // },
        // {
        //   compKey: "buttonKey1",
        //   text: "暂存",
        //   size: "small",
        //   type: "",
        //   clickEvent: () => this.tempsave(),
        //   isShow: true
        // }
      ],
      // 标题
      textMap: {
        // edit: "变更人车关系",
        // add: "变更人车关系"
      },
      formField: {
        custName: "",
        gender: "",
        contactTel: "",
        backupTel: "",
        serverOrder: this.$route.params.serverOrder,
        //serverId:this.$route.params.serverId,
        useCustName: "",
        useGenderCode: "",
        usePhone: "",
        useBackupTel: "",
        cantactWayCode: "",
        infoChanMCode: "",
        infoChanDCode: "",
        clueLevelCode: "",
        dlrCode: this.$store.getters.orgInfo.DLR_CODE,
        nextCallbackDate: "",
        inteSeriesCode: "",
        inteSeriesId: "",
        inteTypeCode: "",
        inteTypeId: "",
        inteTypeName: "",
        clueDesc: "",
        remark: "",
        handleCode: "",
        carBrandCode: "",
        carBrandName: "",
        infoChanDName: "",
        cantactWayName: "",
        infoChanMName: "",
        //渠道来源
        infoChanName: "",
        carSeriesCn: "",
        custClassCode:"",
        carSeriesId:"",
      },
      aArriveReview: "",
      bArriveReview: "",
      hArriveReview: "",
      custNo:"",
    };
  },
  mounted() {
    this.$nextTick(function() {
      if (this.$route.params.serverOrder) {
        this.initData();
      }
      this.getFactSysConf();
    });
  },
  methods: {
    // 查询
    query(api, row, params) {
      let that = this;
      let queryObj = {
        type: "query",
        apiConfig: api,
        apiServices: [
          {
            apiQueryRow: row
          }
        ],
        variables: {
          dataInfo: params
        }
      };
      var paramD = that.$getParams(queryObj);
      requestAPI(paramD).then(response => {
        if (response.result == "1") {
          let results = response.rows[0];
          for (let key in this.formField) {
            if (results.hasOwnProperty(key)) {
              this.formField[key] = results[key];
            }
          }
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.msg
          );
        }
      });
    },

    initQuery(api, row, params) {
      let that = this;
      let queryObj = {
        type: "query",
        apiConfig: api,
        apiServices: [
          {
            apiQueryRow: row
          }
        ],
        variables: {
          dataInfo: params
        }
      };
      var paramD = that.$getParams(queryObj);
      requestAPI(paramD).then(response => {
        if (response.result == "1") {
          let results = response.rows[0];
          for (let key in this.formField) {
            if (results.hasOwnProperty(key)) {
              this.formField[key] = results[key];
            }
          }
          this.formField.infoChanName =
            this.formField.cantactWayName +
            "<" +
            this.formField.infoChanMName +
            "<" +
            this.formField.infoChanDName;
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.msg
          );
        }
      });
    },

    initData() {
      let params = {
        custName: "",
        contactTel: "",
        inteSeriesId: "",
        clueLevelCode: "",
        createdDateStart: "",
        createdDateEnd: "",
        status: "",
        csr: "",
        serverOrder: this.$route.params.serverOrder,
        cantactWayCode: "",
        infoChanMCode: "",
        carBrandCode: "",
        assignStatus: "",
        crruNode: "",
        orderDateStart: "",
        orderDateEnd: "",
        createdName: "",
        dlrCode: "",
        handleCode: "1",
        statusArray: ["10", "20", "21", "30", "31", "40", "50"]
      };
      // 基本信息
      let requiredRow1 = [
        "custName",
        "contactTel",
        "gender",
        "backupTel",
        "useCustName",
        "useGenderCode",
        "usePhone",
        "useBackupTel",
        "clueLevelCode",
        "inteTypeCode",
        "inteTypeId",
        "inteTypeName",
        "inteSeriesCode",
        "inteSeriesId",
        "carBrandName",
        "carSeriesCn",
        "cantactWayName",
        "cantactWayCode",
        "infoChanMName",
        "infoChanMCode",
        "infoChanDName",
        "infoChanDCode",
        "serverOrder",
        "reviewStatusName",
        "createdName",
        "nextCallbackDate",
        "remainDataDate",
        "statusName",
        "crruNodeName",
        "caEmpName",
        "csr",
        "clueDesc",
        "remark"
      ];

      this.initQuery(crmApis.clueServerQueryFromDlr, requiredRow1, params);
    },
    //获取系统配置
    getFactSysConf() {
      let that = this;
      let queryObj = {
        type: "query",
        // api配置
        apiConfig: crmApis.csDbSystemConfigQueryHost,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: [
              "oemClueAssgin",
              "oemClueRecoverTime",
              "clueAutoNotInvalid",
              "firstReviewKpi",
              "aArriveReview",
              "bArriveReview",
              "cArriveReview",
              "eArriveReview",
              "hArriveReview",
              "validClue",
              "invalidClue",
              "cluePools",
              "oemCode",
              "oemId",
              "updateControlId",
              "systemConfigId",
              "isDcc",
              "clueAutoInvalid",
              "failContrloIsCheck"
            ]
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          pageSize: 10,
          pageIndex: 1,
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {
            oemId: this.$store.getters.orgInfo.OEM_ID //根据厂家ID去查找--this.$store.getters.orgInfo
          }
        }
      };
      //转换了中台请求格式数据
      var paramD = this.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.result == "1"
          //&&response.rows != ""
        ) {
          let results = response.rows[0];
          this.aArriveReview = results["aArriveReview"];
          this.bArriveReview = results["bArriveReview"];
          this.hArriveReview = results["hArriveReview"];
          this.levelChange(this.formField.clueLevelCode);
        }
      });
    },
    //意向级别change
    levelChange(val) {
      console.log(val);
      let curDate = new Date().getTime();
      if (val == "A") {
        this.formField.nextCallbackDate = this.transformTime(
          new Date(curDate + this.aArriveReview * 24 * 3600 * 1000)
        );
      } else if (val == "B") {
        this.formField.nextCallbackDate = this.transformTime(
          new Date(curDate + this.bArriveReview * 24 * 3600 * 1000)
        );
      } else if (val == "H") {
        this.formField.nextCallbackDate = this.transformTime(
          new Date(curDate + this.hArriveReview * 24 * 3600 * 1000)
        );
      } else {
        this.formField.nextCallbackDate = "";
      }
    },
    transformTime(time) {
      var y = time.getFullYear();
      var M = time.getMonth() + 1;
      var d = time.getDate();
      // var h = time.getHours();
      // var m = time.getMinutes();
      // var s = time.getSeconds();
      return (
        y + "-" + this.addZero(M) + "-" + this.addZero(d) + " " + "00:00:00"
      );
    },
    addZero(m) {
      return m < 10 ? "0" + m : m;
    },
    //保存
    save() {
      let that = this;
      that.formField.handleCode = "1";
      // validpopup  弹窗  validpage 页面
      delete that.$refs.multipleTable[0].$refs.compKey1
      that.$utils.validataMoth(that, "crmpage");
      this.saveForm();
      // if (this.valid) {
      //   this.saveForm();
      // }
    },
    //保存
    tempsave() {
      let that = this;
      that.formField.handleCode = "0";
      // this.formField// validpopup  弹窗  validpage 页面
      this.$utils.validataMoth(this, "crmpage");
      if (this.valid) {
        this.saveForm();
      }
    },
    saveForm() {
      //保存表单
      let that = this;
      let vaild = true;
      var html = "";
      if (that.formField.custName == "" || that.formField.custName == null) {
        html = html + `<div class="sys-alertDiv">客户名称不能为空</div>`;
      }
      if (
        that.formField.contactTel == "" ||
        that.formField.contactTel == null
      ) {
        html = html + `<div class="sys-alertDiv">电话不能为空</div>`;
      }
      if (that.formField.gender == "" || that.formField.gender == null) {
        html = html + `<div class="sys-alertDiv">性别不能为空</div>`;
      }
      if (
        that.formField.cantactWayCode == "" ||
        that.formField.cantactWayCode == null
      ) {
        html = html + `<div class="sys-alertDiv">信息来源不能为空</div>`;
      }
      //   if (that.formField.infoChanMCode == ""||that.formField.infoChanMCode==null) {
      //   html = html + `<div>渠道大类不能为空</div>`;
      // }
      //   if (that.formField.infoChanDCode == ""||that.formField.infoChanDCode==null) {
      //   html = html + `<div>渠道小类不能为空</div>`;
      // }
      if (
        that.formField.clueLevelCode == "" ||
        that.formField.clueLevelCode == null
      ) {
        html = html + `<div class="sys-alertDiv">意向级别不能为空</div>`;
      }
      if (
        that.formField.inteSeriesId == "" ||
        that.formField.inteSeriesId == null
      ) {
        html = html + `<div class="sys-alertDiv">意向车系不能为空</div>`;
      }
      if (
        that.formField.inteTypeId == "" ||
        that.formField.inteTypeId == null
      ) {
        html = html + `<div class="sys-alertDiv">意向车型不能为空</div>`;
      }
      if (
        that.formField.nextCallbackDate == "" ||
        that.formField.nextCallbackDate == null
      ) {
        html = html + `<div class="sys-alertDiv">下次回访时间不能为空</div>`;
      }
      if(!that.formField.clueDesc){
        html = html + `<div class="sys-alertDiv">描述不能为空</div>`;
      }
      if (html != "") {
        this.$crmcf.showMessages(this, "error", html, true);
        return;
      }
      let vaildParams = {
        custName: [
          "simpleName",
          that.formField.custName,
          `<div>请输入1~20个字的客户名称</div>`
        ],
        contactTel: [
          "telOrphone",
          that.formField.contactTel,
          `<div>请输入正确的电话（手机或座机号码）！</div>`
        ],
        backupTel: [
          "telOrphone",
          that.formField.backupTel,
          `<div>请输入正确的备用电话（手机或座机号码）！</div>`
        ],
        useCustName: [
          "simpleName",
          that.formField.useCustName,
          `<div>请输入1~20个字的用车人姓名</div>`
        ],
        usePhone: [
          "telOrphone",
          that.formField.usePhone,
          `<div>请输入正确的用车人电话（手机或座机号码）！</div>`
        ],
        useBackupTel: [
          "telOrphone",
          that.formField.useBackupTel,
          `<div>请输入正确的用车备用电话（手机或座机号码）！</div>`
        ]
      };
      vaild = this.$crmcf.regex(this, vaildParams);
      if (!vaild) {
        return;
      }
      delete that.formField.infoChanName;
      delete that.formField.carSeriesId;
      delete that.formField.smallCarTypeId;
      delete that.formField.smallCarTypeCn;
      let queryObj = {
        // api配置
        type: "mutation",
        apiConfig: crmApis.clueServerMutationCreateClueOrder,

        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: this.formField
        }
      };
      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.result == "1"
          // &&response.rows != ""
        ) {
          that.$crmcf.showMessages(that, "success", "保存成功！");
          for (var key in that.formField) {
            that.formField[key] = "";
          }

          this.crmSourceFromThis.modelText = "";
          // that.$crmcf.crmcloseView(that);
          //  $($('#tags-view-container .contextmenu li')[0]).click()
        } else {
          that.$crmcf.showMessages(
            that,
            "error",
            response.msg
          );
        }
      });
    },
    //获取意向车型弹出框返回值
    getCarType(rowData) {
      let results = rowData[0];
      this.formField.inteTypeCode = results["smallCarTypeCode"];
      this.formField.inteTypeId = results["smallCarTypeId"];
      this.formField.inteTypeName = results["smallCarTypeCn"];
      this.formField.inteSeriesCode = results["carSeriesCode"];
      this.formField.inteSeriesId = results["carSeriesId"];
    },
    // 获取意向车系
    getCarSeries(rowData) {
      this.formField.inteTypeCode=''
      let results = rowData[0];
      this.formField.inteSeriesCode = results["carSeriesCode"];
      this.formField.inteSeriesId = results["carSeriesId"];
      this.formField.carBrandCode = results["carBrandCode"];
    },
    //渠道来源
    changeSource(rowData, _this) {
      let results = rowData[0];
      this.formField.cantactWayCode = results.cantactWayCode;
      this.formField.infoChanMCode = results.infoChanMCode;
      this.formField.infoChanDCode = results.infoChanDCode;
      this.crmSourceFromThis = _this;
      // this.formField.infoChanDName=results.cantactWayName+'>'+redata[0].infoChanMName+'>'+redata[0].infoChanDName;
    },
    // 客户名称
    getCustName1(rowData, that) {
      if (rowData.custName) {
        let results = rowData;
        this.formField.custName = results.custName;
        this.formField.contactTel = results.phone;
        this.formField.gender = results.genderCode;
        this.custNo=results.dlrCustNo;
        this.formField.custClassCode=results.custClassCode
        this.formField.carSeriesCn = "";
        this.formField.inteSeriesCode = "";
      } else {
        let results = rowData;
        this.formField.custName = results.custName;
        this.formField.contactTel = results.phone;
        this.formField.gender = results.genderCode;
        this.formField.carBrand = results.carBrandCode;
        this.custNo=results.dlrCustNo;
        this.formField.custClassCode=results.custClassCode
        this.formField.carSeriesCn = "";
        this.formField.inteSeriesCode = "";
      }
      this.initCustLXData(this.custNo)
      if (that) {
        that.fastOtherShow = false;
      }
    },
    //加载客户联系信息
    initCustLXData(inCustNo) {
      let that = this;
      let queryObj = {
        // api配置
        apiConfig: crmApis.custViewContactWayQueryFindAll,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: [
              "backupPhone",
            ]
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          pageSize: 10,
          pageIndex: 1,
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {
            dlrCustNo: inCustNo,
          }
        }
      };
      //转换了中台请求格式数据
      var paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (response.result == "1") {
          let results = response.rows[0];
          this.formField.backupTel=results.backupPhone
        }
      });
    },
    getCustName(rowData) {
      let results = rowData[0];
      this.formField.contactTel = results.phone;
      this.formField.gender = results.genderCode;
      this.formField.carBrand = results.carBrandCode;
    },
    sendMessg() {
      this.$refs.sendMsg.curPopupsVisible = true;
      this.$refs.sendMsg.formField.phone = this.formField.contactTel;
    },
    jumpHref() {
      this.$router.push({
        path: "/crmModule/crmyxmodule/crmclueMange/ToDoTaskClueCultivation",
        query: { type: "1" }
      });
      console.log(this);
    },
    //垂直媒体
    dlrSave(){
      this.editPopupsVisible = false
      // this.$refs.addDlr.curPopupsVisible=true
      this.editRowData={}
      this.editPopupsState = 'add'
      this.editPopupsVisible = true
      this.editPopupsKey = this.$utils.generateId()
    },
    //车系列表change
    serieSelect(val,code,text,txt){
      this.formField.inteSeriesId=val;
      this.formField.inteTypeId="";
      this.formField.smallCarTypeId="";
    },
    //车型列表change
    carTypeSelect(val,txt,obj){
      console.log(val,txt,obj)
      this.formField.inteTypeId = val;
      this.formField.inteTypeName = txt;
      this.formField.inteTypeCode = obj.smallCarTypeCode;
      this.formField.carBrandCode = obj.carBrandCode;
      this.formField.inteSeriesCode = obj.carSeriesCode;
    }
  }
};
</script>
<style scoped>
.choosefile {
  float: left;
  text-align: left;
}
.filter-params-crm-scroll{
  margin-top: 0!important;
}
.crm-s-scroll{
    margin-left: 0!important;
}
</style>
